<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>代码自动生成</title>
</head>
<body>
    <div class="item">
        <div class="item-form">
            <form action="" method="get">
                <h2 style="text-align: center">生成CURD</h2>
                <div>
                    <div class="left">table_name：</div>
                    <div class="right">
                        <input type="text" name="table_name" placeholder="请输入模型名称，下划线隔开" value="<?=$data['table_name'] ?>"><span style="color: red">必填</span>
                    </div>
                </div>
                <div>
                    <div class="left">service_name：</div>
                    <div class="right">
                        <input type="text" name="service_name" placeholder="请输入服务名称，下划线隔开" value="<?=@$data['service_name'] ?>"><span style="color: red">必填：script.manage.base</span>
                    </div>
                </div>
                <div>
                    <div class="left">root_path_name：</div>
                    <div class="right">
                        <input type="text" name="root_path_name" placeholder="服务所在目录" value="<?=@$data['root_path_name'] ?>"><span style="color: red">必填:code.inke.cn/inno/blackcat/server/room</span>
                    </div>
                </div>
                <hr>
                <div>
                    <div class="left">Redis client name：</div>
                    <div class="right">
                        <input type="text" name="redis_client_name" placeholder="redis的客户端名称" value="<?=$data['redis_client_name'] ?>"><span style="color: red">*非必填【redis的客户端名称，默认是：redis】</span>
                    </div>
                </div>
                <hr>
                <div>
                    <div class="left">program_file_path：</div>
                    <div class="right">
                        <input type="text" name="file_path" placeholder="请输入项目文件路径" value="<?=$data['file_path'] ?>"><span style="color: red">非必填，如填写，并且是目录，则会生成可生成的文件</span>
                    </div>
                </div>
                <div>
                    <div class="left">是否生成代码文件：</div>
                    <div class="right">
                        <select name="gen_code">
                            <option value ="1" <?php if($data['gen_code'] == 1) echo "selected='selected'"; ?>>是</option>
                            <option value ="0" <?php if($data['gen_code'] == 0) echo "selected='selected'"; ?>>否</option>
                        </select>
                    </div>
                </div>
                <div>
                    <div class="left">git_branch：</div>
                    <div class="right">
                        <input type="text" name="branch" placeholder="请输入git分支" value="<?=$data['branch'] ?>"><span style="color: red">非必填，如填写，则会切换到该分支进行提交</span>
                    </div>
                </div>
                <hr>
                <h2 style="text-align: center">生成SDK</h2>
                <h2 style="text-align: left;color: red">请注意：参数的结构体里一定要有schema字段</h2>
                <div>
                    <div class="left">SDK_function_desc：</div>
                    <div class="right">
                        <input type="text" name="function_desc" placeholder="请输入方法描述：这个方法是拿来干什么事儿的" value="<?=@$data['function_desc'] ?>"><span style="color: red">用来定义方法描述</span>
                    </div>
                </div>
                <div>
                    <div class="left">SDK_function_name：</div>
                    <div class="right">
                        <input type="text" name="function_name" placeholder="请输入方法名称：GetClubRooms" value="<?=@$data['function_name'] ?>"><span style="color: red">用来定义方法名称</span>
                    </div>
                </div>
                <div>
                    <div class="left">SDK_uri_const：</div>
                    <div class="right">
                        <input type="text" name="uri_const" placeholder="请输入接口地址的常量名称：MyActivityURI" value="<?=@$data['uri_const'] ?>"><span style="color: red">请输入接口地址的常量名称->MyActivityURI</span>
                    </div>
                </div>
                <div>
                    <div class="left">SDK_uri：</div>
                    <div class="right">
                        <input type="text" name="uri" placeholder="请输入接口地址的常量名称：/api/user/detail" value="<?=@$data['uri'] ?>"><span style="color: red">请输入接口地址->/api/user/detail</span>
                    </div>
                </div>
                <div>
                    <div class="left">SDK_method：</div>
                    <div class="right">
                        <select name="method">
                            <option value ="GET" <?php if($data['method'] == "GET") echo "selected='selected'"; ?>>GET</option>
                            <option value ="POST" <?php if($data['method'] == "POST") echo "selected='selected'"; ?>>POST</option>
                        </select>
                    </div>
                </div>
                <div>
                    <input type="submit">
                </div>
            </form>
        </div>
    </div>
<!--    dao-->

    <div class="item">
        <?php if (!empty($data['function_name'])):?>
            <div class="item-son">
                <h2>SDK：手动拷贝</h2>
                <div class="text">
        <textarea name="" id="dao_redis" cols="50" rows="30">
                        <?= $this->render('sdk', ['data' => @$data]); ?>
                    </textarea>
                </div>
            </div>
        <?php endif;?>
        <!--    table-->
        <?php if (!empty($data['table_name'])):?>
            <div class="item-son">
                <h2>curd_model：可生成文件</h2>
                <div class="text">
    <textarea name="" id="dao_mysql" cols="50" rows="30">
                    <?php echo $model = $this->render('curd_model', ['data' => @$data]); ?>
                    <?php if ($data['gen_code'] ) file_put_contents($data['file_path'] . "/model/" . $data['table_name'].'.go', $model);?>
                </textarea>
                </div>
            </div>

            <div class="item-son">
                <h2>dao：手动拷贝</h2>
                <div class="text">
    <textarea name="" id="dao_mysql" cols="50" rows="30">
                    <?php echo $dao =  $this->render('dao', ['data' => @$data]); ?>
                </textarea>
                </div>
            </div>

            <div class="item-son">
                <h2>dao_mysql：可生成文件</h2>
                <div class="text">
    <textarea name="" id="dao_mysql" cols="50" rows="30">
                    <?php echo $dao_mysql = $this->render('dao_mysql', ['data' => @$data]); ?>
                    <?php if ($data['gen_code'] ) file_put_contents($data['file_path'] . "/dao/" . $data['table_name']."_mysql.go", $dao_mysql);?>
                </textarea>
                </div>
            </div>

            <div class="item-son">
                <h2>dao_redis：可生成文件</h2>
                <div class="text">
    <textarea name="" id="dao_redis" cols="50" rows="30">
                    <?php echo $dao_redis = $this->render('dao_redis', ['data' => @$data]); ?>
                    <?php if ($data['gen_code'] ) file_put_contents($data['file_path'] . "/dao/" . $data['table_name']."_redis.go", $dao_redis);?>
                </textarea>
                </div>
            </div>
        <?php endif;?>

        <!--    service-->
        <?php if (!empty($data['service_name'])):?>
            <div class="item-son">
                <h2>curd_router：手动拷贝</h2>
                <div class="text">
<textarea name="" id="dao_mysql" cols="50" rows="30">
                <?php echo  $router = $this->render('curd_router', ['data' => @$data]); ?>
                <?php
                        //router必然存在，这个判断失效，不能生成
//                    $router_file = $data['file_path'] . "/server/http/router.go";
//                    if ($data['gen_code'] && !fileExists($router_file)){
//                        file_put_contents($router_file, $model);
//                    }
                ?>
            </textarea>
                </div>
            </div>

            <div class="item-son">
                <h2>curd_mgr：手动拷贝</h2>
                <div class="text">
<textarea name="" id="dao_redis" cols="50" rows="30">
                <?= $this->render('curd_mgr', ['data' => @$data]); ?>
            </textarea>
                </div>
            </div>

            <div class="item-son">
                <h2>curd_http：可生成文件</h2>
                <div class="text">
<textarea name="" id="dao_redis" cols="50" rows="30">
                <?php echo $http = $this->render('curd_http', ['data' => @$data]); ?>
                <?php if ($data['gen_code'] ) file_put_contents($data['file_path'] . "/server/http/" . $data['table_name'].'.go', $http);?>
            </textarea>
                </div>
            </div>

            <div class="item-son">
                <h2>curd_service：可生成文件</h2>
                <div class="text">
<textarea name="" id="dao_redis" cols="50" rows="30">
                <?php echo $service = $this->render('curd_service', ['data' => @$data]); ?>
                <?php if ($data['gen_code'] ) file_put_contents($data['file_path'] . "/service/" . $data['table_name'].'.go', $service);?>
            </textarea>
                </div>
            </div>
        <?php endif;?>

        <div class="item-son">
            <h2>curd_code：手动拷贝</h2>
            <div class="text">
        <textarea name="" id="dao_redis" cols="50" rows="30">
                        <?= $this->render('curd_code', ['data' => @$data]); ?>
                    </textarea>
            </div>
        </div>
    </div>




    <div class="item">

    </div>

    <div class="item">

    </div>

    <div class="item">

    </div>
    <?php
        //执行命令，提交代码
//        $checkout = $data['branch'] ? "git checkout {$data['branch']} &&": "";
//        $cmd = "cd {$data['file_path']} && {$checkout} git add . && git commit -am \"auto gen code\" && git push ";
//        exec($cmd,$res_exe);
//        foreach ($res_exe as $key=>$item) {
//            $res_exe[$key]=trim($item);
//        }
    ?>
</body>
<style>
    /*.item{*/
    /*    background-color: red;*/
    /*}*/
    .item-son{
        display: inline-block;
        padding-right: 100px;
    }

    input[type=text]{
        width: 300px;
    }

    .left{
        display: inline-block;
        width: 22%;
    }

    .right{
        display: inline-block;
    }
</style>
</html>